/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sistemabienes;

import com.sun.data.provider.RowKey;
import com.sun.data.provider.impl.CachedRowSetDataProvider;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Button;
import com.sun.webui.jsf.component.Calendar;
import com.sun.webui.jsf.component.DropDown;
import com.sun.webui.jsf.component.Label;
import com.sun.webui.jsf.component.TableRowGroup;
import com.sun.webui.jsf.component.TextArea;
import com.sun.webui.jsf.component.TextField;
import com.sun.webui.jsf.model.DefaultTableDataProvider;
import com.sun.webui.jsf.model.MultipleSelectOptionsList;
import com.sun.webui.jsf.model.SingleSelectOptionsList;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import javax.faces.FacesException;
import javax.faces.convert.BigDecimalConverter;
import javax.faces.event.ValueChangeEvent;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @version RegActivos.java
 * @version Created on 03-11-2011, 11:58:16 PM
 * @author luis
 */

public class RegActivos extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
        
        activo_registroDataProvider1.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.activo_registroRowSet1}"));
        grupos_contablesDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.grupos_contablesRowSet}"));
        activoBuscarDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.activoBuscarRowSet}"));
        
        dropDown2DefaultOptions.setOptions(new com.sun.webui.jsf.model.Option[]{new com.sun.webui.jsf.model.Option("1", "EDIFICACIONES"), new com.sun.webui.jsf.model.Option("2", "TERRENOS"), new com.sun.webui.jsf.model.Option("3", " MUEBLES Y ENSERES DE OFICINA"), new com.sun.webui.jsf.model.Option("4", " EQUIPO MEDICO Y DE LABORATORIO"), new com.sun.webui.jsf.model.Option("5", "HERRAMIENTAS EN GENERAL"), new com.sun.webui.jsf.model.Option("6", "EQUIPO DE COMUNICACIONES"), new com.sun.webui.jsf.model.Option("7", "EQUIPOS DE COMPUTACION"), new com.sun.webui.jsf.model.Option("8", "OTROS ACTIVOS FIJOS"), new com.sun.webui.jsf.model.Option("9", "VEHICULOS AUTOMOTORES"), new com.sun.webui.jsf.model.Option("10", "ACTIVOS EN DESUSO"), new com.sun.webui.jsf.model.Option("11", "MAQUINARIA EN GENERAL"), new com.sun.webui.jsf.model.Option("12", "EQUIPO EDUCACIONAL Y RECREATIVO")});
        
       
        
    }
    private CachedRowSetDataProvider activo_registroDataProvider1 = new CachedRowSetDataProvider();

    public CachedRowSetDataProvider getActivo_registroDataProvider1() {
        return activo_registroDataProvider1;
    }

    public void setActivo_registroDataProvider1(CachedRowSetDataProvider crsdp) {
        this.activo_registroDataProvider1 = crsdp;
    }
    private CachedRowSetDataProvider grupos_contablesDataProvider = new CachedRowSetDataProvider();

    public CachedRowSetDataProvider getGrupos_contablesDataProvider() {
        return grupos_contablesDataProvider;
    }

    public void setGrupos_contablesDataProvider(CachedRowSetDataProvider crsdp) {
        this.grupos_contablesDataProvider = crsdp;
    }
    private BigDecimalConverter cbmodifGrupoConverter = new BigDecimalConverter();

    public BigDecimalConverter getCbmodifGrupoConverter() {
        return cbmodifGrupoConverter;
    }

    public void setCbmodifGrupoConverter(BigDecimalConverter bdc) {
        this.cbmodifGrupoConverter = bdc;
    }
    private TextField txtcod_bien = new TextField();

    public TextField getTxtcod_bien() {
        return txtcod_bien;
    }

    public void setTxtcod_bien(TextField tf) {
        this.txtcod_bien = tf;
    }
    private TextArea txtdescActivo = new TextArea();

    public TextArea getTxtdescActivo() {
        return txtdescActivo;
    }

    public void setTxtdescActivo(TextArea ta) {
        this.txtdescActivo = ta;
    }
    private TextField txtprecioAdq = new TextField();

    public TextField getTxtprecioAdq() {
        return txtprecioAdq;
    }

    public void setTxtprecioAdq(TextField tf) {
        this.txtprecioAdq = tf;
    }
    private TextField txtnombre = new TextField();

    public TextField getTxtnombre() {
        return txtnombre;
    }

    public void setTxtnombre(TextField tf) {
        this.txtnombre = tf;
    }
    private TextField txtnroSerie = new TextField();

    public TextField getTxtnroSerie() {
        return txtnroSerie;
    }

    public void setTxtnroSerie(TextField tf) {
        this.txtnroSerie = tf;
    }
    private TextField txtvida_util = new TextField();

    public TextField getTxtvida_util() {
        return txtvida_util;
    }

    public void setTxtvida_util(TextField tf) {
        this.txtvida_util = tf;
    }
    private TextField txtUfv = new TextField();

    public TextField getTxtUfv() {
        return txtUfv;
    }

    public void setTxtUfv(TextField tf) {
        this.txtUfv = tf;
    }
    private Calendar calfechaAdq = new Calendar();

    public Calendar getCalfechaAdq() {
        return calfechaAdq;
    }

    public void setCalfechaAdq(Calendar c) {
        this.calfechaAdq = c;
    }
    private BigDecimalConverter dropDown1Converter = new BigDecimalConverter();

    public BigDecimalConverter getDropDown1Converter() {
        return dropDown1Converter;
    }

    public void setDropDown1Converter(BigDecimalConverter bdc) {
        this.dropDown1Converter = bdc;
    }
    private DropDown dropDown1 = new DropDown();

    public DropDown getDropDown1() {
        return dropDown1;
    }

    public void setDropDown1(DropDown dd) {
        this.dropDown1 = dd;
    }
    private Label lblkeybien = new Label();

    public Label getLblkeybien() {
        return lblkeybien;
    }

    public void setLblkeybien(Label l) {
        this.lblkeybien = l;
    }
    private CachedRowSetDataProvider activoBuscarDataProvider = new CachedRowSetDataProvider();

    public CachedRowSetDataProvider getActivoBuscarDataProvider() {
        return activoBuscarDataProvider;
    }

    public void setActivoBuscarDataProvider(CachedRowSetDataProvider crsdp) {
        this.activoBuscarDataProvider = crsdp;
    }
    private TextField textBuscaCod = new TextField();

    public TextField getTextBuscaCod() {
        return textBuscaCod;
    }

    public void setTextBuscaCod(TextField tf) {
        this.textBuscaCod = tf;
    }
    private TextField txtmodifNombre = new TextField();

    public TextField getTxtmodifNombre() {
        return txtmodifNombre;
    }

    public void setTxtmodifNombre(TextField tf) {
        this.txtmodifNombre = tf;
    }
    private TextField txtModifAnyo = new TextField();

    public TextField getTxtModifAnyo() {
        return txtModifAnyo;
    }

    public void setTxtModifAnyo(TextField tf) {
        this.txtModifAnyo = tf;
    }
    private TextField txtmodifUfv = new TextField();

    public TextField getTxtmodifUfv() {
        return txtmodifUfv;
    }

    public void setTxtmodifUfv(TextField tf) {
        this.txtmodifUfv = tf;
    }
    private TextField txtModifSerie = new TextField();

    public TextField getTxtModifSerie() {
        return txtModifSerie;
    }

    public void setTxtModifSerie(TextField tf) {
        this.txtModifSerie = tf;
    }
    private Calendar calendarModifAdq = new Calendar();

    public Calendar getCalendarModifAdq() {
        return calendarModifAdq;
    }

    public void setCalendarModifAdq(Calendar c) {
        this.calendarModifAdq = c;
    }
    private TableRowGroup tableRowGroup3 = new TableRowGroup();

    public TableRowGroup getTableRowGroup3() {
        return tableRowGroup3;
    }

    public void setTableRowGroup3(TableRowGroup trg) {
        this.tableRowGroup3 = trg;
    }
    private TextField txtmodif_cod = new TextField();

    public TextField getTxtmodif_cod() {
        return txtmodif_cod;
    }

    public void setTxtmodif_cod(TextField tf) {
        this.txtmodif_cod = tf;
    }
    private TextArea txtmodifdesc = new TextArea();

    public TextArea getTxtmodifdesc() {
        return txtmodifdesc;
    }

    public void setTxtmodifdesc(TextArea ta) {
        this.txtmodifdesc = ta;
    }
    private TextField txtmodifPrecioAdq = new TextField();

    public TextField getTxtmodifPrecioAdq() {
        return txtmodifPrecioAdq;
    }

    public void setTxtmodifPrecioAdq(TextField tf) {
        this.txtmodifPrecioAdq = tf;
    }
    private Calendar calendar1 = new Calendar();

    public Calendar getCalendar1() {
        return calendar1;
    }

    public void setCalendar1(Calendar c) {
        this.calendar1 = c;
    }
    private TableRowGroup tableRowGroup2 = new TableRowGroup();

    public TableRowGroup getTableRowGroup2() {
        return tableRowGroup2;
    }

    public void setTableRowGroup2(TableRowGroup trg) {
        this.tableRowGroup2 = trg;
    }
    private SingleSelectOptionsList dropDown2DefaultOptions = new SingleSelectOptionsList();

    public SingleSelectOptionsList getDropDown2DefaultOptions() {
        return dropDown2DefaultOptions;
    }

    public void setDropDown2DefaultOptions(SingleSelectOptionsList ssol) {
        this.dropDown2DefaultOptions = ssol;
    }
    private DropDown dropDown2 = new DropDown();

    public DropDown getDropDown2() {
        return dropDown2;
    }

    public void setDropDown2(DropDown dd) {
        this.dropDown2 = dd;
    }
    private TableRowGroup tableRowGroup1 = new TableRowGroup();

    public TableRowGroup getTableRowGroup1() {
        return tableRowGroup1;
    }

    public void setTableRowGroup1(TableRowGroup trg) {
        this.tableRowGroup1 = trg;
    }

    // </editor-fold>

    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public RegActivos() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
      /*  try{
            URL url = new URL("http://www.bcb.gob.bo/rss_bcb.php");
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            String resultado="";
            while ((line = reader.readLine()) != null ) {
                //resultado=resultado+line;
                //textArea1.setText(resultado);
                 if(line.indexOf("UFV =") != -1)
                 {
                     int e = line.indexOf("UFV =");
                     String r=line;
                     String v=r.substring(e+8, e+15);
                     String valor=v.replace(',', '.');
                     txtUfv.setText(valor);

                      break;
                }

            }

            reader.close();

         /*   int i=resultado.indexOf("Bs1");
            if(i!= -1)
           {
               //int r = resultado.indexOf("Bs1");
           String v=resultado.substring(i+2, i+9);
           //res.setText(resultado.indexOf("Bs1"));

           txtufv.setText(v.replace(',', '.'));
           resultado="";
            }


        } catch (MalformedURLException e) {
            // ...
        } catch (IOException e) {
            // ...
        }*/


        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("RegActivos Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
        calendar1.setText(this.getSessionBean1().getFecha());
        calfechaAdq.setText(this.getSessionBean1().getFecha());
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
        activo_registroDataProvider1.close();
        grupos_contablesDataProvider.close();
        activoBuscarDataProvider.close();
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

   

    public String btncancelar_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        return null;
    }



    

     public int buscar_max_cod_bien() throws NamingException
    {
        int secuencia=0;
            try{
                String dataSourceName=
                        this.getSessionBean1().getActivo_registroRowSet1().getDataSourceName();
                 Context ctx= new InitialContext();
                 DataSource ds=(DataSource) ctx.lookup(dataSourceName);

                 CallableStatement cs1 = ds.getConnection().prepareCall("select max(keybien) as secuencia from activo");
                   ResultSet rs=cs1.executeQuery();
                 if(rs.next())
                 {
                     int valor=rs.getInt(1);
                     secuencia=valor+1;
                     rs.close();
                      return secuencia;
                 }
                  /* do
                   {

                   }while (rs.next());*/


     }catch(SQLException e)
            {
                error(e.getMessage());

            }

        return 0;
    }


private String max_cod_bien;
    /**
     * @return the max_cod_bien
     */
    public String getMax_cod_bien() throws NamingException {


            try{
                String dataSourceName=
                        this.getSessionBean1().getActivo_registroRowSet1().getDataSourceName();
                 Context ctx= new InitialContext();
                 DataSource ds=(DataSource) ctx.lookup(dataSourceName);

                 CallableStatement cs1 = ds.getConnection().prepareCall("select max(keybien) as secuencia from activo");
                   ResultSet rs=cs1.executeQuery();
                 if(rs.next())
                 {
                     int valor=rs.getInt(1);
                     
                     int suma=valor+1;
                     setMax_keybien(suma);
                    String secuencia=String.valueOf(suma);
                    String keyb="1-"+secuencia;
                    max_cod_bien=keyb;
                     rs.close();
                      return max_cod_bien;
                 }
                  /* do
                   {

                   }while (rs.next());*/


     }catch(SQLException e)
            {
                error(e.getMessage());

            }
        return max_cod_bien;
    }

    /**
     * @param max_cod_bien the max_cod_bien to set
     */
    public void setMax_cod_bien(String max_cod_bien) {
        this.max_cod_bien = max_cod_bien;
    }
        private int max_keybien;

         /**
     * @return the max_keybien
     */
    public int getMax_keybien() {
        return max_keybien;
    }

    /**
     * @param max_keybien the max_keybien to set
     */
    public void setMax_keybien(int max_keybien) {
        this.max_keybien = max_keybien;
    }



    public void dropDown1_processValueChange(ValueChangeEvent event) throws NamingException {
             int kpartida=Integer.parseInt(dropDown1.getValue().toString());
           //cbdep1.setSelected(kpartida);
       int secuencia;
            try{
                String dataSourceName=
                        this.getSessionBean1().getActivo_registroRowSet1().getDataSourceName();
                 Context ctx= new InitialContext();
                 DataSource ds=(DataSource) ctx.lookup(dataSourceName);

                 CallableStatement cs1 = ds.getConnection().prepareCall("select  anyos from grupos_contables where keygrupo=?");
                 cs1.setInt(1, kpartida);
                 ResultSet rs=cs1.executeQuery();
                 if(rs.next())
                 {
                     int valor=rs.getInt(1);
                     secuencia=valor*12;
                     txtvida_util.setText(secuencia);
                     rs.close();
                     cs1.close();
                     ctx.close();

                 }
                  /* do
                   {

                   }while (rs.next());*/


     }catch(SQLException e)
            {
                error(e.getMessage());

            }
    }

    public String button1_action() throws NamingException, SQLException {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        if(txtdescActivo.getText().equals("-") || txtnombre.getText().equals("-") || txtnroSerie.getText().equals("-") || txtprecioAdq.getText().equals("-"))
        {
                error("No se admiten campos vacios");
        }
         else
        {
            int keyb=Integer.parseInt(lblkeybien.getText().toString());
            int keyp=Integer.parseInt(dropDown1.getValue().toString());
            String codb=txtcod_bien.getText().toString();
            String desc=txtdescActivo.getText().toString();
            int vidaini=Integer.parseInt(txtvida_util.getText().toString());
            float valorini= Float.valueOf(txtprecioAdq.getText().toString());
            String serie= txtnroSerie.getText().toString();
            String nom= txtnombre.getText().toString();
            Date fechAdq= calfechaAdq.getSelectedDate();
            float ufvini= Float.valueOf(txtUfv.getText().toString());
            insertaActivo(keyb, keyp, codb, desc, vidaini, valorini, serie, nom, fechAdq, ufvini);
            int seccion=getSessionBean1().getSeccion();
            this.getSessionBean1().getActivoBuscarRowSet().setCommand("select * from ACTIVOS.ACTIVO where keyseccion=? order by keybien desc");
            this.getSessionBean1().getActivoBuscarRowSet().setInt(1, seccion);
            activoBuscarDataProvider.refresh();

        activo_registroDataProvider1.refresh();
            
                info("Se inserto correctamente el bien");
         }
            return null;
    }

    public void insertaActivo(int keybien,int keypart,String codb,String descb,int vidainicial,float valorinicial,String seriec,String nombre,Date FechaAdqui,float ufvini) throws NamingException
    {
        int secuencia=0;
            try{
                String dataSourceName=
                        this.getSessionBean1().getActivo_registroRowSet1().getDataSourceName();
                 Context ctx= new InitialContext();
                 DataSource ds=(DataSource) ctx.lookup(dataSourceName);

                 CallableStatement cs1 = ds.getConnection().prepareCall("CALL activos.INSERTA_ACTIVO(?,?,?,?,?,?,?,?,?,?)");
                 cs1.setInt(1, keybien);
                 cs1.setInt(2, keypart);
                 cs1.setString(3,codb);
                 cs1.setString(4,descb);
                 cs1.setInt(5, vidainicial);
                 cs1.setFloat(6, valorinicial);
                 cs1.setString(7,seriec);
                 cs1.setString(8,nombre);
                 cs1.setDate(9,new java.sql.Date(FechaAdqui.getTime()));
                 cs1.setFloat(10,ufvini);
                 cs1.execute();
                 cs1.close();
                 ctx.close();
                 

                  this.pasarGarbageCollector();
     }catch(SQLException e)
            {
                error(e.getMessage());

            }

    }
    public void pasarGarbageCollector(){

        Runtime garbage = Runtime.getRuntime();
        System.out.println("Memoria libre antes de limpieza: "+ garbage.freeMemory());

        garbage.gc();

        System.out.println("Memoria libre tras la limpieza: "+ garbage.freeMemory());
    }

    public String button3_action() throws SQLException {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        String codb=textBuscaCod.getText().toString();
        this.getSessionBean1().getActivoBuscarRowSet().setCommand("select * from activo where cod_bien like ?");
        this.getSessionBean1().getActivoBuscarRowSet().setString(1, codb);
        activoBuscarDataProvider.refresh();
        return null;
    }

    

    public void btnMoficarAct_action() throws NamingException {
        // TODO: Replace with your code
        String val="-";
        String codb=txtmodif_cod.getText().toString();
        String desc=txtmodifdesc.getText().toString();
        String v_ini= txtmodifPrecioAdq.getText().toString();
        String nombre=txtmodifNombre.getText().toString();
        String tiempo_vida=txtModifAnyo.getText().toString();
        String keypartida=dropDown2.getValue().toString();
         String serie=txtModifSerie.getText().toString();
        if(codb.equals(val) || desc.equals(val) || desc.equals(val)  || v_ini.equals(val) || nombre.equals(val) || tiempo_vida.equals(val) || serie.equals(val) ){
            error("Campos requeridos!!");
        }else{
        float valorini=Float.valueOf(v_ini);
        int tvida=Integer.parseInt(tiempo_vida);
        int keypart=Integer.parseInt(keypartida);
       
        Date modifAdq=calendarModifAdq.getSelectedDate();
        updateActivo(codb, desc, modifAdq, keypart, nombre, serie, valorini, tvida);
        activoBuscarDataProvider.refresh();
        activo_registroDataProvider1.refresh();
        error("Se actualizo correctamente");
        }
    }
    
    public void updateActivo(String codb,String descb,Date FechaAdqui, int keypart,String nombre,String seriec,float valorinicial,int vidainicial) throws NamingException
    {
        int secuencia=0;
            try{
                String dataSourceName=
                        this.getSessionBean1().getActivoBuscarRowSet().getDataSourceName();
                 Context ctx= new InitialContext();
                 DataSource ds=(DataSource) ctx.lookup(dataSourceName);

                 CallableStatement cs1 = ds.getConnection().prepareCall("CALL activos.UPDATE_ACTIVO(?,?,?,?,?,?,?,?)");
                 cs1.setInt(1, keypart);
                 cs1.setString(2,codb);
                 cs1.setString(3,descb);
                  cs1.setInt(4, vidainicial);
                  cs1.setFloat(5, valorinicial);
                  cs1.setString(6,seriec);  
                  cs1.setString(7,nombre);
                  cs1.setDate(8,new java.sql.Date(FechaAdqui.getTime()));
                 cs1.execute();
                 cs1.close();
                 ctx.close();
     }catch(SQLException e)
            {
                error(e.getMessage());

            }

    }


    public String tab2_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        return null;
    }

    public String Editar_action() {
        // TODO: Replace with your code
        RowKey rk = tableRowGroup2.getRowKey();
        String codb=activoBuscarDataProvider.getValue("COD_BIEN",rk).toString();
        String desc=activoBuscarDataProvider.getValue("DESCRIPCION",rk).toString();
        String valorini=activoBuscarDataProvider.getValue("VALOR_INI",rk).toString();
        String nom=null;
        if(activoBuscarDataProvider.getValue("NOMBRE",rk)!=null)
        {
            nom=activoBuscarDataProvider.getValue("NOMBRE",rk).toString();
        }else{ nom="-";}
        
        
        String tiempov=activoBuscarDataProvider.getValue("TIEMPO_VIDA_INICIO",rk).toString();
        String keyp=activoBuscarDataProvider.getValue("KEYPARTIDA",rk).toString();
        String ufvini=activoBuscarDataProvider.getValue("UFV_INI",rk).toString();
        String serie=activoBuscarDataProvider.getValue("NRO_SERIE",rk).toString();
        String fechadq= activoBuscarDataProvider.getValue("FECHA_ADQUISICION",rk).toString();
        txtmodif_cod.setText(codb);
        txtmodifdesc.setText(desc);
        txtmodifPrecioAdq.setText(valorini.replace(",", "."));
        txtmodifNombre.setText(nom);
        txtModifAnyo.setText(tiempov);
        getDropDown2().setSelected(keyp);
        txtmodifUfv.setText(ufvini);
        txtModifSerie.setText(serie);
        calendarModifAdq.setText(fechadq);
        return null;
    }

    public void dropDown2_processValueChange(ValueChangeEvent event) throws NamingException {
        int kpartida=Integer.parseInt(dropDown2.getValue().toString());
           //cbdep1.setSelected(kpartida);
       int secuencia;
            try{
                String dataSourceName=
                        this.getSessionBean1().getActivo_registroRowSet1().getDataSourceName();
                 Context ctx= new InitialContext();
                 DataSource ds=(DataSource) ctx.lookup(dataSourceName);

                 CallableStatement cs1 = ds.getConnection().prepareCall("select  anyos from grupos_contables where keygrupo=?");
                 cs1.setInt(1, kpartida);
                 ResultSet rs=cs1.executeQuery();
                 if(rs.next())
                 {
                     int valor=rs.getInt(1);
                     secuencia=valor*12;
                     txtModifAnyo.setText(secuencia);
                     rs.close();
                     cs1.close();
                     ctx.close();
                 }

                  /* do
                   {

                   }while (rs.next());*/


     }catch(SQLException e)
            {
                error(e.getMessage());

            }
    }

    public String imprime_codBarras_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        getSessionBean1().setTipoReporte("application/pdf");
        RowKey rk = tableRowGroup1.getRowKey();
        String codbarras=activo_registroDataProvider1.getValue("COD_BIEN",rk).toString();
        getSessionBean1().setCod_barra(codbarras);
        return "cod_barras";
    }

    public String btnguardargrupoc1_action() {
        // TODO: Replace with your code
        return null;
    }


   
    
}

